//
//  GEdwardJTOAPPInter.m
//  GDHEdwardLive
//
//  Created by 高得华 on 2017/6/18.
//  Copyright © 2017年 高得华. All rights reserved.
//

#import "GEdwardJTOAPPInter.h"
#import <UserNotifications/UserNotifications.h>

@interface GEdwardJTOAPPInter ()

@end

@implementation GEdwardJTOAPPInter

/**
 1. 跳转到 打电话
 
 @param tel 电话号码 tel
 */
+ (void) GESharedTel:(NSString *)tel {
    if (tel.length <= 0) return;
    NSString * telUrl = [NSString stringWithFormat:@"tel://%@",tel];
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:telUrl]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telUrl]];
    }
}

/**
 2. 跳转到 发邮件
 
 @param mailto 邮件地址
 */
+ (void) GESharedMail:(NSString *)mailto {
    if (mailto.length <= 0) return;
    NSString * telUrl = [NSString stringWithFormat:@"mailto://%@",mailto];
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:telUrl]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telUrl]];
    }
}

/**
 3. 调用自带 浏览器
 
 @param safari 网址地址
 */
+ (void) GESharedSafari:(NSString *)safari {
    if (safari.length <= 0) return;
    NSString * telUrl = [NSString stringWithFormat:@"%@",safari];
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:telUrl]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telUrl]];
    }
}

/**
 4. 调用短信 SMS
 
 @param SMS 电话号码
 */
+ (void) GESharedSMS:(NSString *)SMS {
    if (SMS.length <= 0) return;
    NSString * telUrl = [NSString stringWithFormat:@"sms://%@",SMS];
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:telUrl]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telUrl]];
    }
}

/**
 5. 调用 app Store
 
 @param appstore appstore description
 */
+ (void) GESharedAppStore:(NSString *)appstore {
    NSString * telUrl = [NSString stringWithFormat:@"itms-apps://"];
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:telUrl]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telUrl]];
    }
}

/**
 6. 调用 iBook
 
 @param iBook appstore description
 */
+ (void) GESharediBook:(NSString *)iBook {
    NSString * telUrl = [NSString stringWithFormat:@"itms-books://"];
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:telUrl]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telUrl]];
    }
}

/**
 7. 调用 Map
 
 @param Map appstore description
 */
+ (void) GESharedMap:(NSString *)Map {
    NSString * telUrl = [NSString stringWithFormat:@"maps://"];
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:telUrl]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telUrl]];
    }
}

/**
 7. 调用 Facetime
 
 @param facetime facetime帐号
 */
+ (void) GESharedFacetime:(NSString *)facetime {
    if (facetime.length <= 0) return;
    NSString * telUrl = [NSString stringWithFormat:@"facetime://%@",facetime];
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:telUrl]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:telUrl]];
    }
}

/**
 8. 跳转到AppStore评分
 
 @param appId App的唯一标志符
 @param isHome 评分界面 或者 软件首页进行下载
 */
+ (void) GESharedGiveMark:(NSString *)appId isHome:(BOOL)isHome {
    if (isHome) {
        NSString *str = [NSString stringWithFormat: @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@", appId];
        if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:str]]) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
        }
    }else {
        NSString *str2 = [NSString stringWithFormat: @"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=%@",  appId];
        if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:str2]]) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str2]];
        }
    }
}

/**
 9.跳转到系统设置界面
 
 @param url Url
 */
+ (void) GEShareOpenURL:(NSString *)url {
    if (url.length <= 0) return;
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:url]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
    }
}





#pragma mark - ===== 设置权限 ===== -
///1.0 推送相关
+ (void)openMessageNotificationServiceWithBlock:(GEdwardJTOAPPInterBlock)returnBlock
{
    BOOL isOpen = NO;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0
    UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
    if (setting.types != UIUserNotificationTypeNone) {
        isOpen = YES;
    }
#else
    UIRemoteNotificationType type = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
    if (type != UIRemoteNotificationTypeNone) {
        isOpen = YES;
    }
#endif
    if (returnBlock) {
        returnBlock(isOpen);
    }
}

@end
